home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume4 / tvx / part08 < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  44.9 KB

  1. From: talcott!seismo!gatech!unmvax!wampler (Bruce Wampler)
  2. Subject: tvx: 8 of 10
  3. Newsgroups: mod.sources
  4. Approved: jpn@panda.UUCP
  5.  
  6. Mod.sources:  Volume 4, Issue 22
  7. Submitted by: gatech!unmvax!wampler (Bruce Wampler)
  8.  
  9. #--------CUT---------CUT---------CUT---------CUT--------#
  10. #########################################################
  11. #  TVX: File 8 of 10                                    #
  12. #                                                       #
  13. # This is a shell archive file.  To extract files:      #
  14. #                                                       #
  15. #    1)    Make a directory (like tvx) for the files.      #
  16. #    2) Write a file, such as "filen.shar", containing  #
  17. #       this archive file into the directory.           #
  18. #    3) Type "sh file.shar".  Do not use csh.           #
  19. #                                                       #
  20. #########################################################
  21. #
  22. #
  23. echo Extracting tvx_lex.c:
  24. sed 's/^X//' >tvx_lex.c <<\SHAR_EOF
  25. X/* -------------------------- tvx_lex.c --------------------------- */
  26. X#include "tvx_defs.ic"
  27. X
  28. X/* -------------------------- GLOBALS GO HERE -------------------------------*/
  29. X#define EXTERN
  30. X
  31. X#include "tvx_glbl.ic"
  32. X
  33. X   char clower(),cupper();
  34. X
  35. X/* =============================>>> CHECKOS <<<============================= */
  36. X  checkos()
  37. X  {
  38. X    /* check if ok operating system */
  39. X#ifdef MSDOS
  40. X    if ((bdos(0x30,0) & 0xff) < 2)        /* !!! cii-86 dependent */
  41. X      {
  42. X    remark("TVX requires MS-DOS 2.0 or later");
  43. X    exit();
  44. X      }
  45. X#endif
  46. X  }
  47. X
  48. X/* =============================>>> STARTM <<<============================= */
  49. X  startm()
  50. X  {
  51. X    prompt(START_IDM);
  52. X    prompt(VERSION); prompt("Terminal: ");
  53. X    remark(cversn);
  54. X    remark("");
  55. X    starthelp();
  56. X  }
  57. X
  58. X/* =============================>>> STARTHELP <<<============================= */
  59. X  starthelp()        /* print start help message */
  60. X  {
  61. X    remark(START_HELPM); remark("");
  62. X  }
  63. X
  64. X
  65. X/* =============================>>> MEMORY <<<============================= */
  66. X  memory()
  67. X  { /* memory - print memory left */
  68. X    SLOW int nxt;
  69. X    SLOW unsigned int tmp;
  70. X
  71. X    char value[10],msg[85],*cp;
  72. X    if (bakflg)
  73. X    return;            /* don't do this during logfile input */
  74. X
  75. X    nxt=0;            /* where message goes */
  76. X    cp = (*dest_file ? dest_file : orig_file);
  77. X    strcopy(cp,max(strlen(cp)-36,0),msg,&nxt);    /* the file name */
  78. X    if (nxt <= 14)
  79. X     {
  80. X       strcopy(VERSION,0,msg,&nxt); /* TVX */
  81. X       strcopy(cversn,0,msg,&nxt);  /* terminal type */
  82. X     }
  83. X    strcopy(" Free chars:",0,msg,&nxt);    /* add ' Free chars: ' */
  84. X
  85. X#ifdef LASL
  86. X    tmp = max(nxtsav - nxtchr - BUFFLIMIT,0);
  87. X#else
  88. X    tmp = nxtsav - nxtchr;
  89. X#endif
  90. X
  91. X#ifdef INT16
  92. X    if (tmp > 30000)        /* handle "neg" size */
  93. X      {
  94. X    msg[nxt++] = '+';
  95. X    tmp -= 30000;
  96. X      }
  97. X#endif
  98. X    itoa(tmp,value);
  99. X    strcopy(value,0,msg,&nxt);    /* the value */
  100. X    strcopy(" Line:",0,msg,&nxt);    /* add ' Line: ' */
  101. X    itoa(curlin,value);
  102. X    strcopy(value,0,msg,&nxt);
  103. X    strcopy(" of ",0,msg,&nxt);
  104. X    itoa(nxtlin-1,value);
  105. X    strcopy(value,0,msg,&nxt);    /* add the count */
  106. X    tverr(msg);     /* display line on screen */
  107. X }
  108. X/* =============================>>> SHOSET  <<<============================= */
  109. X  shoset()
  110. X  {  /* show repeat buffer, help if available */
  111. X
  112. X#ifdef HELP
  113. X    static char rp[2];
  114. X    FAST int i;
  115. X    SLOW char *cp, *msg;
  116. X    SLOW int fields, oldtty, hnum;
  117. X    SLOW unsigned tmp;
  118. X
  119. X#ifdef TVX_CMDSET
  120. X#ifdef FULLHELP
  121. X    struct help_msg 
  122. X      {
  123. X    char *hmsg;
  124. X    char Vmsg;
  125. X      };
  126. X
  127. X    static struct help_msg cmddes[] =    /* messages for help */
  128. X      {
  129. X    {"nApnd to sv buff", VSAPPEND},    {" Buffer beg     ",    VTOP},
  130. X    {" File beg",         VFBEGIN},    {"nChange chars   ",    VCHANGE},
  131. X    {"nDown line      ", VDOWNLINE},{"nDown column",    VDOWNCOL},
  132. X    {" Buffer end     ", VBOTTOM},    {"nEdit rpt buffer",    VEDITRPT},
  133. X    {"nFind",            VSEARCH},    {" Find cross-buff",    VNEXT},
  134. X    {" Get save buffer", VGET},    {" Unkill lastline",    VUNKILL},
  135. X    {"nHalf page      ", VHALFP},    {"nInsert (to ESC)",    VINSERT},
  136. X    {" Jump back",         VJUMP},    {"nKill character ",    VDELNEXT},
  137. X    {"nKill line      ", VKILLALL},    {"nLeft",        VLEFT},
  138. X    {" Memory status  ", VMEMORY},    {"nNote location  ",    VNOTELOC},
  139. X    {"nReset loc",         VRETNOTE},    {"nOpen line      ",    VOPENLINE},
  140. X    {" Call Opr system", VSYSTEM},    {"nPage",        VFLIP},
  141. X    {" Print screen   ", VPRINTS},    {"nRight          ",    VRIGHT},
  142. X    {" Restore rpt buf", VSTORERPT},{"nSave lines     ",    VSAVE},
  143. X    {"nTidy, fill text", VTIDY},    {" Abort",        VABORT},
  144. X    {"nUp             ", VUPLINE},    {"nUp column      ",    VUPCOL},
  145. X    {" Verify screen",   VVERIFY},    {"nWrite buffer   ",    VWPAGE},
  146. X    {" Exit, end edit ", VQUIT},    {"nYank file",        VYANK},
  147. X    {"nDel prev char  ", VDELLAST},    {"nFind again     ",    VSAGAIN},
  148. X    {" Del last",         VREMOVE},    {" Change last    ",    VRMVINS},
  149. X    {" Del to line beg", VKILLPREV},{" Del to line end",    VKILLREST},
  150. X    {" Line begining  ", VBEGLINE},    {" Line end       ",    VENDLINE},
  151. X    {"nWord right",         VMVWORD},    {"nWord left      ",    VMVBWORD},
  152. X    {"nRepeat again   ", VXREPEAT},    {"nk Exec rpt k n times",VEXECRPT},
  153. X    {"n p Set param p ", VSETPARS},    {" Help           ",    VHELP},
  154. X    {" Insert find pat", VINSPAT},    {"nToggle case    ",    VFOLDCASE},
  155. X    {"/",0}            /* last variable entry */
  156. X      };
  157. X#endif
  158. X#endif
  159. X
  160. X    if (bakflg)
  161. X    return;            /* don't do this during logfile input */
  162. X
  163. X    oldtty = ttymode;
  164. X    ttymode = FALSE;
  165. X    if (!oldtty)
  166. X    tvclr();
  167. X
  168. X    prompt("Parameter : cur val (1=y, 0=n)    Prev 16 cmds:");
  169. X    for (hnum = 0,i = old_cindex ; hnum < 16 ; ++hnum)
  170. X      {
  171. X    shocout(old_cmds[i]);
  172. X    i = ++i % 16;
  173. X      }
  174. X
  175. X    remark("");
  176. X    prompt("A-Autoindent: "); wtint(autoin);
  177. X    prompt("  C-Cut mode: "); wtint(cut_mode);
  178. X    prompt("  E-Expand tabs: "); wtint(tabspc);
  179. X    prompt("  T-TTY mode: "); wtint(ttymode); remark("");
  180. X
  181. X    prompt("F-Find: ignore case: "); 
  182. X    if (xcases)
  183. X        tvcout('0');
  184. X    else
  185. X        tvcout('1');
  186. X
  187. X    prompt("    M-Match wild cards: "); wtint(use_wild); remark("");
  188. X    prompt("U-User wild card set: |");
  189. X    for (cp = user_set ; *cp ; ++cp)
  190. X      {
  191. X    shocout(*cp);
  192. X      }
  193. X    remark("|");
  194. X
  195. X    prompt("D disp line:"); wtint(dsplin); 
  196. X    prompt("  S-Scroll window:"); wtint(scroll);
  197. X    prompt("  V-Virtual window:"); wtint(tvlins); 
  198. X    prompt("/"); wtint(tvhardlines);
  199. X    prompt("  W-Wrap width:"); wtint(wraplm); remark("");
  200. X    prompt("O-Output file: "); prompt(dest_file);
  201. X    prompt("  (input file is: ");prompt(orig_file); remark(")");
  202. X    remark("");
  203. X
  204. X    prompt("Find: |");
  205. X    for (cp = sbuff ; *cp ; ++cp)
  206. X      {
  207. X    shocout(*cp);
  208. X      }
  209. X    remark("|");
  210. X    remark("");
  211. X    prompt("Max chars: ");
  212. X    tmp = mxbuff;
  213. X#ifdef INT16
  214. X    if (tmp > 30000)        /* handle "neg" size */
  215. X      {
  216. X    prompt("30000+");
  217. X    tmp -= 30000;
  218. X      }
  219. X#endif
  220. X    wtint(tmp); prompt("  Max lines: ");    wtint(mxline);
  221. X    prompt("  Cur line: "); wtint(curlin);
  222. X    if (usecz)
  223. X    prompt("    ^Z for EOF");
  224. X    remark("");
  225. X    remark("");
  226. X
  227. X    prompt("R-Repeat buffer: ");wtint(rptuse+1);
  228. X    remark("   All repeat buffers : <contents>:");
  229. X    for (i = 0 ; i < REPEATBUFS ; ++ i)
  230. X      {
  231. X    fields = 5;
  232. X    shocout('#') ; shocout(i+'1') ; prompt(": <");
  233. X    for (cp = &rptbuf[i][0] ; *cp ; ++cp)
  234. X      {
  235. X        shocout(*cp);
  236. X        ++fields;        /* how many letters */
  237. X        if (*cp < ' ')
  238. X        ++fields;
  239. X        if (fields >= (tvcols - 6))
  240. X          {
  241. X        prompt("+more+");
  242. X        break;
  243. X          }
  244. X      }
  245. X    remark(">");
  246. X      }
  247. X
  248. X    ttymode = oldtty;
  249. X    memory();
  250. X
  251. X#ifdef FULLHELP
  252. X    tvxy(1,22);
  253. X
  254. X    ask("Press space to exit, anything else for command list ",rp,1);
  255. X
  256. X    if (*rp == ' ')
  257. X      {
  258. X    ttymode = oldtty;
  259. X    verify(1);
  260. X    return;
  261. X      }
  262. X
  263. X    if (!oldtty)
  264. X    tvclr();
  265. X
  266. X/* ------------------------------ TVX ----------------------------------- */
  267. X#ifdef TVX_EM
  268. X    remark("Commands (n => count allowed):");
  269. X#endif
  270. X#ifdef TVX0M_EM
  271. X    remark("Commands (n => count allowed) (Non ^ cmds prefixed by ESC):");
  272. X#endif
  273. X
  274. X#ifdef TVX_CMDSET
  275. X    for (hnum = fields = 0  ; ; ++hnum )
  276. X      {
  277. X    prompt("   ");
  278. X    cp = cmddes[hnum].hmsg;
  279. X    if (*cp == '/')    /* end of variable list */
  280. X        break;
  281. X    else
  282. X        shocout(*cp);    /* show n or blank */
  283. X    msg = ++cp;        /* where message is, skipping 'n' field */
  284. X    while (*cp)        /* ship to lex value */
  285. X        ++cp;
  286. X    i = cmddes[hnum].Vmsg;        /* get the lexical index */
  287. X    shocout(cupper(lexsym[i]));    /* show the command */
  288. X    if (lexsym[i] >= ' ')
  289. X        shocout(' ');    /* skip space for no '^' */
  290. X
  291. X    shocout(' ');        /* space to separate */
  292. X    prompt(msg);        /* and show the message */
  293. X    if (++fields == 3)    /* bump fields, see if need newline */
  294. X      {
  295. X        fields = 0;
  296. X        remark("");
  297. X      }
  298. X      }
  299. X    if (fields != 0)
  300. X    remark("");
  301. X#endif        
  302. X#ifdef TVX_EM
  303. X    remark("   n<>$$:Rpt loop        @:Invoke cmd file      $:Escape");
  304. X#endif
  305. X#ifdef TVX0M_EM
  306. X    remark("  $n<>$$:Rpt loop       $@:Invoke cmd file      $:Escape");
  307. X#endif
  308. X
  309. X/* ------------------------------ VI ----------------------------------- */
  310. X#ifdef VI_EM
  311. X    remark("Commands (n => count allowed):");
  312. Xremark("");
  313. Xremark("n^B:scrn up     n^D:half scrn   n^F:scrn dwn    ^G:status     ^L:refresh");
  314. Xremark("n^U:up half scr n!:tidy         n#p:ex rpt p n   $:line end    *:ins last pat");
  315. Xremark("/:search         =:help           ?:rev search  @:exec rpt lp");
  316. Xremark("A:apnd ln end   C:chng rest ln  D:del rest line  nG:Goto ln n  H:buff beg");
  317. Xremark("I:ins ln beg    J:join lines    nK:up: line beg  L:buff end    nM:ret to mark");
  318. Xremark("N:rev find nxt  nO:open above   P:put sv buf abv");
  319. Xremark("q:'tvx' prefix: q!:op system    qb:file begin    qu:limited undo"); 
  320. Xremark("nq:p:set par p nqe:ed rpt buf   qj:jump back     qp:put file   qy: yank file");
  321. Xremark("                qs:print scr    nqw:write buf   nqr:restore rpt q/:x-buff find");
  322. Xremark("nX:del prev ch  nY:apnd sv buf  Z:[Z:exit,A:abort]             ^:line begin");
  323. Xremark("a:append        nb:word left    c:chng [c,<sp>,^,$,/]      nd:del [d,<sp>,^,$,/]");
  324. Xremark("ni:insert       nh:left         nj:down in col   nk:up line in col");
  325. Xremark("nl:right        nm:mark loc     n:find next pat  no:open after");
  326. Xremark("p:put sv buf after              r:replace 1 chr  ns:substitute");
  327. Xremark("nw:word right   nx:delete chr   ny:yank to save buffer          n~:change case");
  328. X    remark("");
  329. Xremark("n<>$$:Rpt loop  _:Invoke cmd file   $:Escape");
  330. X    remark("'c/' and 'd/' are used to change/delete last thing found");
  331. X#endif
  332. X
  333. X/* ------------------------------ EMAX ----------------------------------- */
  334. X#ifdef EMAX_EM
  335. Xremark("(n means count allowed: counts entered after <esc> or <ctrl-u>)");
  336. Xremark("");
  337. Xremark("^A:line beg    n^B:back chrs                 n^C:extended tvx commands:");
  338. Xremark("");
  339. Xremark("[n^A:apnd sv   ^B: file beg   n^C:chng chrs  n^E:Ed rpt bf   n^F:fill        ]");
  340. Xremark("[ ^G:no op    n^H:half scrn    ^J:jmp back    ^K:kill 'last'  n^N:next ln    ]");
  341. Xremark("[n^M:mark loc n^P:Prev ln      ^R:Restore rbf ^W:write buff    ;:search again]");
  342. Xremark("[n~:chng case  nG:Goto line    nH:Half pg up  nI:ins val n     L: Print scrn ]");
  343. Xremark("[nM:rtn 2 mrk  nP:Put sv bf     S:x buff find  U:unkill 1 ln nVp:set val(par)]");
  344. Xremark("[ R:Read file into sv buff      W:write sv buff to file   *:insert found pat ]");
  345. Xremark("");
  346. Xremark("n^D:del chr    ^E:line end    n^F:fwrd chr   n^H:del prev ch  n^K:kill line");
  347. Xremark(" ^L:repaint   n^N:next ln     n^O:open ln    n^P:prev ln       ^R:rev search");
  348. Xremark(" ^S:search     ^U:specify n  n^V:page dwn   ^X^C:abort edit");
  349. Xremark("^X^B:status  n^XE:ex. rpt bf  ^Y:yank sv bf   ^Z:write, exit");
  350. Xremark(" $%:cmd file   $!:op. sys.   n$#p:ex rpt p   n$(:rpt loop      $<:buff begin");
  351. Xremark(" $>:buff end   $?:help        n$B:back word  n$F:fwd word     n$V:page up");
  352. Xremark("");
  353. Xremark("$ = <esc>,  ')$$' ends repeat loops");
  354. X#endif
  355. X
  356. X
  357. X#ifdef GEMDOS
  358. X    remark("Find wild cards:  {TVX command '(' toggles 25/50 line display}");
  359. X#else
  360. X    remark("Find wild cards:");
  361. X#endif
  362. Xremark("^A-alphanumeric  ^D-digit  ^L-letter  ^O-other,(not-^A)  ^P-punctuation");
  363. Xremark("^X-any character ^U-user set  -- ^W-word of ^..  ^N-not in word of ^..");
  364. X
  365. X#endif
  366. X
  367. X    if (!oldtty)
  368. X    tvxy(1,24);
  369. X    ask("Press any key to resume ",rp,1);
  370. X
  371. X    ttymode = oldtty;
  372. X
  373. X    verify(1);
  374. X#else                /* HELP not defined */
  375. X    tverr(&rptbuf[rptuse][0]);
  376. X#endif
  377. X  }
  378. X
  379. X/* =============================>>> SHOCOUT <<<============================= */
  380. X  shocout(c)
  381. X  char c;
  382. X  {
  383. X
  384. X    if (c < ' ')
  385. X      {
  386. X    ttwt('^'); ttwt(c + '@');
  387. X      }
  388. X    else
  389. X    ttwt(c);
  390. X  }
  391. X
  392. X/* =============================>>> LEXGET <<<============================= */
  393. X  lexget(chr)
  394. X  char *chr;
  395. X  {  /* lexget - get a character for lex, possibly from repeat buffer */
  396. X
  397. X    SLOW char tmp;
  398. Xl10:
  399. X    if (rptcnt[rptuse] > 0)    /* in a repeat buffer? */
  400. X      {
  401. X    *chr=rptbuf[rptuse][nxtrpt[rptuse]];    /* pick up from repeat buffer */
  402. X    if (*chr == 0)     /* at end of rpt buff */
  403. X      {
  404. X        nxtrpt[rptuse] = 0;    /* start <> loop over */
  405. X        if (--rptcnt[rptuse] == 0 && !echof)    /* all done with loop */
  406. X          {
  407. X        echof = TRUE;    /* turn on echo again */
  408. X        newscr();    /* update screen after repeat */
  409. X          }
  410. X        goto l10;        /* loop again */
  411. X      }
  412. X    ++nxtrpt[rptuse];    /* bump to next char in loop */
  413. X      }
  414. X    else            /* not in loop, get from keyboard */
  415. X      {
  416. X    gkbd(&tmp);    /* picks up one character from the keyboard */
  417. X    *chr = old_cmds[old_cindex] = tmp;
  418. X    old_cindex = ++old_cindex % 16;
  419. X      }
  420. X  }
  421. X
  422. X/* =============================>>> LEX    <<<============================= */
  423. X  lex(lexval,lexcnt,lexchr,parsok)
  424. X  int *lexval,*lexcnt,parsok;
  425. X  char *lexchr;
  426. X  { /* ##  lex - gets command input from terminal, and scans for
  427. X       #  its lexical value.  Returns a count if given.  Also handles
  428. X       #  repeat loops. */
  429. X    SLOW int count, lex_default;
  430. X    FAST int i;
  431. X    SLOW int neg, newln;
  432. X
  433. X    static char chr,cmdchr,tchr;
  434. X#ifdef EMAX_EM
  435. X    SLOW char had_cu;
  436. X#endif
  437. X
  438. X    lex_default = TRUE;
  439. X
  440. X    if (!parsok)        /* abort if error in <> */
  441. X      {
  442. X    if (rptcnt[rptuse] > 0)    /* in loop? */
  443. X      {
  444. X        newscr();    /* clear screen, send message */
  445. X        tverrb("<> not complete ");
  446. X      }
  447. X    rptcnt[rptuse]=0;    /* abort loop if going */
  448. X    nxtrpt[rptuse]=0;
  449. X      }
  450. Xl10:
  451. X    for (;;) 
  452. X      {             /* need this loop to support <> */
  453. X    count = 1;        /* default count is 1 */
  454. X    lexget(&chr);        /* fetch a character */
  455. X#ifdef EMAX_EM
  456. X    had_cu = FALSE;        /* not ^U initially */
  457. XCU_COUNT:
  458. X    if (chr == 21)        /* ctrl-u count detect */
  459. X      {
  460. X        if (had_cu)
  461. X        fixend();
  462. X        count *= 4;        /* assume 4 by default */
  463. X        tvmsg("Arg: ",FALSE); /* echo Arg: 4' */
  464. X        wtint(count);
  465. X        had_cu = TRUE;    /* remember we had control-u */
  466. X        lex_default = FALSE; /* and not the default */
  467. X        lexget(&chr);
  468. X      }
  469. X#endif
  470. X#ifdef NOMODE_LEX
  471. X    if ( ((chr & 0177) >= ' ' || chr == TAB || chr == CR)
  472. X      && (chr & 0200) == 0)
  473. X      {
  474. X#ifdef EMAX_EM
  475. X        if (had_cu)
  476. X          {
  477. X        had_cu = FALSE;
  478. X        fixend();
  479. X        if ((chr >= '0' && chr <= '9') || chr == '-')
  480. X            goto EMAX_CNT;
  481. X          }
  482. X        for (i = 0 ; i < count ; ++i)    /* ^U times */
  483. X#endif
  484. X        ins_chr((int) chr);    /* simply insert the character */
  485. X        continue;        /* get next character */
  486. X      }
  487. X    if (chr == escape_chr)    /* if an escape, simply get next char */
  488. X        lexget(&chr);
  489. X#endif
  490. X
  491. X    if (rptcnt[rptuse]>0 && chr == loop_beg)    /* detect nesting */
  492. X      {
  493. X        nxtrpt[rptuse] = 0 ; rptcnt[rptuse] = 0 ; echof=TRUE;
  494. X        newscr();    /* update anything so far */
  495. X        tverrb("No loop nesting ");
  496. X        continue;
  497. X      }
  498. X#ifdef EMAX_EM
  499. XEMAX_CNT:
  500. X#endif
  501. X    if ((chr>='0' && chr<='9') || chr=='-')    /* a number */
  502. X      {
  503. X        count = 0;  lex_default = FALSE;
  504. X        neg = FALSE;    /* handle negative counts */
  505. X        if (chr=='-')
  506. X        neg=TRUE;
  507. X        else 
  508. X        count = chr-'0';    /* convert to int value */
  509. X        for (;;) 
  510. X          {
  511. X        if (rptcnt[rptuse] > 0)    /* have to handle rptbuf special */
  512. X          {
  513. X            if ((chr=rptbuf[rptuse][nxtrpt[rptuse]]) == 0)
  514. X            break;
  515. X            ++nxtrpt[rptuse];
  516. X          }
  517. X        else 
  518. X            lexget(&chr);
  519. X        if (chr>='0' && chr<='9')    /* another number? */
  520. X            count = count*10+chr-'0';
  521. X        else            /* done with number */
  522. X            break;
  523. X          }
  524. X        if (neg)            /* fix if it was negative */
  525. X        count = min(-count ,-1);
  526. X      }    /* end count arg if */
  527. X
  528. X#ifdef EMAX_EM
  529. X    if (chr == 21)        /* another ^U? */
  530. X        goto CU_COUNT;
  531. X    if (had_cu)
  532. X        fixend();    /* count changes */
  533. X#endif
  534. X
  535. X#ifdef VI_EM
  536. X    cmdchr = chr;        /* vi emulator is case sensitive */
  537. X#else
  538. X    cmdchr = clower(chr);    /* fold to one case */
  539. X#endif
  540. X    if (cmdchr == loop_beg)    /* starting a loop? */
  541. X      {
  542. X        lex_default = TRUE;            /* don't let lex count be def */
  543. X        rptcnt[rptuse] = (count < 0) ? (-count) : count;    /* save count */
  544. X        ins_mode = TRUE;            /* so ttymode works */
  545. X        tvmsg("repeat[",FALSE);        /* echo 'repeat[k]: n<' */
  546. X        wtint(rptuse+1); prompt("]: ");
  547. X        wtint(rptcnt[rptuse]);
  548. X
  549. X        tvcout(loop_beg);
  550. X#ifdef SCR_BUF
  551. X        ttflush();
  552. X#endif
  553. X        nxtrpt[rptuse]=0;    /* begin inserting at beginning */
  554. X        newln = FALSE;    /* no new line echo yet */
  555. X        do            /* fetch repeat chars until get > */
  556. X          {
  557. X        gkbd(&chr);    /* fetch a char */
  558. X        if (chr==delkey)    /* allow editing */
  559. X          {
  560. X            if (nxtrpt[rptuse] > 0)    /* don't go past start */
  561. X              {
  562. X            --nxtrpt[rptuse];    /* wipe out last */
  563. X            if ((tchr = rptbuf[rptuse][nxtrpt[rptuse]])==CR)
  564. X              {
  565. X                ctrlch(CR);    /* going to newline */
  566. X                newln = TRUE;        /* new line now */
  567. X              }
  568. X            else if (!newln)
  569. X              {
  570. X                tvcout(BACKSPACE);    /* back over character */
  571. X                tvcout(' ');
  572. X                tvcout(BACKSPACE);
  573. X                if (tchr < ' ' && tchr != 27)
  574. X                  {
  575. X                tvcout(BACKSPACE);    /* back over char */
  576. X                tvcout(' ');
  577. X                tvcout(BACKSPACE);
  578. X                  }
  579. X              }
  580. X            else        /* have passed new line start */
  581. X              {
  582. X                ctrlch(rptbuf[rptuse][nxtrpt[rptuse]]);
  583. X                tvcout('\\');
  584. X              }
  585. X              }
  586. X            else
  587. X            tvcout(BELL);    /* trying to rubout too much */
  588. X#ifdef SCR_BUF
  589. X            ttflush();
  590. X#endif
  591. X            continue;
  592. X          }
  593. X        else        /* a control character detected */
  594. X            ctrlch(chr);    /* echo */
  595. X#ifdef SCR_BUF
  596. X        ttflush();
  597. X#endif
  598. X        rptbuf[rptuse][nxtrpt[rptuse]]=chr;    /* stuff in current rpt buff. */
  599. X        ++nxtrpt[rptuse];    /* bump count */
  600. X        if (nxtrpt[rptuse] >= 100)    /* only allow 100 chars! */
  601. X          {
  602. X            newscr();
  603. X            tverrb("100 chars only");
  604. X            nxtrpt[rptuse]=0 ; rptcnt[rptuse]=0;
  605. X            ins_mode = FALSE;
  606. X            goto l10;    /* bail out */
  607. X          }
  608. X          }
  609. X        while (!( chr==ESC && rptbuf[rptuse][nxtrpt[rptuse]-2]==ESC &&
  610. X          rptbuf[rptuse][nxtrpt[rptuse]-3]==loop_end));    /* end do loop */
  611. X
  612. X        ins_mode = FALSE;        /* get ttymode right */
  613. X
  614. X        if (rptcnt[rptuse] > 1)    /* positive count? */
  615. X        echof = FALSE;    /* turn off echoing */
  616. X        else if (newln)
  617. X        verify();    /* need to fix up screen because of newline */
  618. X        else        /* 0 or 1 count */
  619. X          {
  620. X        fixend();
  621. X        tvhdln();    /* get back where we were */
  622. X          }
  623. X
  624. X        rptbuf[rptuse][nxtrpt[rptuse]-3] = 0;    /* mark with eos */
  625. X        nxtrpt[rptuse]=0;    /* back for scan now */
  626. X        continue;        /* now execute the loop */
  627. X      }
  628. X#ifdef VB
  629. X    else if (cmdchr == lexsym[0])    /*$$$    indirect files! */
  630. X      {
  631. X        opnatf();
  632. X        continue;
  633. X      }
  634. X#endif
  635. X    for (i=0 ; synofr[i]!=0 ; ++i)
  636. X      if (synofr[i]==cmdchr)
  637. X         cmdchr=synoto[i];        /* allow synonyms */
  638. X    *lexval = UNKNOWN;    /* assume unknown command */
  639. X    for (i = 1 ; i<= LEXVALUES ; ++i)    /* scan all possible cmds */
  640. X        if (cmdchr == lexsym[i])    /* found it */
  641. X          {
  642. X        *lexval = i;
  643. X        break;
  644. X          }
  645. X    *lexcnt = count;        /* return good stuff */
  646. X    *lexchr = chr;
  647. X    return (lex_default);        /* let know if gave back default */
  648. X      }                    /* end of for(;;) */
  649. X  }
  650. X/* -------------------------- tvx_lex.c --------------------------- */
  651. SHAR_EOF
  652. echo Extracting tvx_cfg.c:
  653. sed 's/^X//' >tvx_cfg.c <<\SHAR_EOF
  654. X
  655. X/* -------------------------- tvx_cfg.c --------------------------- */
  656. X#include "tvx_defs.ic"
  657. X
  658. X#define BL remark("")
  659. X
  660. X    char synofr[20] =    /* from table */
  661. X      {' ',13,']',000,000,000,000,000,000,000,00,00,00,00,00,00,00,00,00,00};
  662. X    char synoto[20] =        /* translate to table */
  663. X      {'r','d','{',00,000,0,000,00,00,000,00,00,00,00,00,00,00,00,00,00};
  664. X    char funkey = 0;        /* leading char for function key */
  665. X    char funchar[50] =    /* code sent by function key */
  666. X      {
  667. X    000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  668. X    000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  669. X    000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  670. X    000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  671. X    000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  672. X      };
  673. X    char funcmd[50] =    /* equivalent command */
  674. X      {
  675. X    000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  676. X    000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  677. X    000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  678. X    000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  679. X    000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  680. X      };
  681. X
  682. X/* define standard command set */
  683. X
  684. X    char lexsym[LEXVALUES+1] = { E0, 'r', 'l', 'd', 'u',
  685. X      4, 21, 8, 'k', 'i', 11, '"', '\'', ',', '.', 'f', 6, 'p',
  686. X      'b', 'e', 2, 'v', 'o', '/', 's', 'g', 23, 25, 24, ';', '&',
  687. X      'm', ':', '=', 7, 9, '{', 'a', 16, '?', 'h', 20, 'c', 'j', 't',
  688. X      'n', 14, 15, 5, 18, '#', '*', '(', ')','~' };
  689. X
  690. X
  691. X    char autoin, dsplin, scroll, xcases, warplm, wildch, funesc, cut_mode;
  692. X    char rp[80];
  693. X
  694. X    FILE *f, *fopen();
  695. X    char cupper(), clower();
  696. X
  697. X  main()
  698. X  {
  699. X
  700. X    SLOW int i, val, retcode;
  701. X
  702. X    cls();
  703. X    remark("Standard TVX define a configuration file -- Version 2/27/86");
  704. X    BL;
  705. X    for (;;)
  706. X      {
  707. X    prompt("Enter name of file to save configuration in: ");
  708. X    reply(rp,79);
  709. X    if ((f = fopen(rp,FILEWRITE)) == 0)
  710. X        continue;
  711. X    else
  712. X        break;
  713. X      }
  714. X
  715. X
  716. X    cls();
  717. X    shoset();
  718. X    BL;
  719. X    for (;;)
  720. X      {
  721. X    BL;
  722. X    prompt("Use standard command definitions? (y/n) ");
  723. X    lreply(rp,10);
  724. X    if (*rp == 'y')
  725. X      {
  726. X        goto LEXDONE;
  727. X      }
  728. X    else if (*rp == 'n')
  729. X        break;
  730. X      }
  731. X
  732. XCMDAGAIN:
  733. X    retcode = 1;        /* start with things ok */
  734. X    for (;;)
  735. X      {
  736. X    short_cls();
  737. X    shoset();
  738. X    if (retcode < 0)
  739. X        remark("Invalid value supplied for new command.  Try again!");
  740. X    if ((retcode = set()) == 0)
  741. X        break;
  742. X      }
  743. X    short_cls();
  744. X    shoset();
  745. X    remark("");
  746. X    prompt("Are you finished setting commands? (y/n) ");
  747. X    ureply(rp,2);
  748. X    if (*rp != 'Y')
  749. X    goto CMDAGAIN;
  750. X    
  751. X
  752. X    
  753. X
  754. XLEXDONE:
  755. X    for (i=0 ; i <= LEXVALUES ; ++i)    /* write out lex symbols */
  756. X      {
  757. X    fputc(lexsym[i],f);        /* write to file */
  758. X      }
  759. X    syno();
  760. X    funkeys();
  761. X
  762. X    cls();
  763. X    prompt("Use autoindent (n default) (y/n): ");
  764. X    lreply(rp,10);
  765. X    if (*rp == 'y')
  766. X    fputc(1,f);
  767. X    else 
  768. X    fputc(0,f);
  769. X
  770. X    BL;
  771. X    prompt("Home display line: (1-66, 16 default): ");
  772. X    rdint(&val);
  773. X    if (val > 66 || val <= 0)
  774. X    fputc(16,f);
  775. X    else
  776. X        fputc(val,f);
  777. X
  778. X    BL;
  779. X    prompt("Scroll window (0 default): ");
  780. X    rdint(&val);
  781. X    if (val > 24)
  782. X    val = 0;
  783. X    fputc(val,f);
  784. X
  785. X    BL;
  786. X    prompt("Find case (e=exact,a=any, any default): "); 
  787. X    lreply(rp,10);
  788. X    if (*rp == 'e')
  789. X        fputc(1,f);
  790. X    else
  791. X        fputc(0,f);
  792. X
  793. X    BL;
  794. X
  795. X    prompt("Auto line wrap width (0 default): ");
  796. X    rdint(&val);
  797. X    if (val > 79)
  798. X    val = 0;
  799. X    fputc(val,f);
  800. X
  801. X    BL;
  802. X    prompt("Use wild cards (y default) (y/n)? ");
  803. X    lreply(rp,10);
  804. X    if (*rp == 'n')
  805. X    fputc(0,f);
  806. X    else 
  807. X    fputc(1,f);
  808. X
  809. X    BL;
  810. X    prompt("Use BACKUP.LOG file (n default) (y/n)? ");
  811. X    lreply(rp,10);
  812. X    if (*rp == 'y')
  813. X        fputc(1,f);
  814. X    else
  815. X        fputc(0,f);
  816. X    
  817. X    BL;
  818. Xprompt("Use 'cut mode' (killed lines to save buffer too)? (n default) (y/n)? ");
  819. X    lreply(rp,10);
  820. X    if (*rp == 'y')
  821. X        fputc(1,f);
  822. X    else
  823. X        fputc(0,f);
  824. X
  825. X#ifdef MSDOS
  826. X    BL;
  827. X    remark("The editor can recognize Ctrl-z as EOF, or it can ignore ^Z and");
  828. X    remark("just use the standard MS-DOS end of file mark.");
  829. X    prompt("Should the editor recognize Ctrl-Z as EOF? (n default) (y/n) ");
  830. X    lreply(rp,10);
  831. X    if (*rp == 'y')
  832. X        fputc(1,f);
  833. X    else
  834. X        fputc(0,f);
  835. X#endif
  836. X#ifdef GEMDOS
  837. X    fputc(1,f);        /* use ^Z on gemdos by default */
  838. X#endif
  839. X
  840. X    cls();
  841. X    remark("Configuration file created.");
  842. X    fclose(f);
  843. X  }
  844. X
  845. X/* =============================>>> SHOSET  <<<============================= */
  846. X  shoset()
  847. X  {  /* show repeat buffer, help if available */
  848. X
  849. X    static char rp[2];
  850. X    FAST int i;
  851. X    SLOW char *cp, *msg;
  852. X    SLOW int fields, oldtty, hnum;
  853. X    SLOW unsigned tmp;
  854. X
  855. X    struct help_msg 
  856. X      {
  857. X    char *hmsg;
  858. X    char Vmsg;
  859. X      };
  860. X
  861. X    static struct help_msg cmddes[] =    /* messages for help */
  862. X      {
  863. X    {"nApnd to sv buff", VSAPPEND},    {" Buffer beg     ",    VTOP},
  864. X    {" File beg",         VFBEGIN},    {"nChange chars   ",    VCHANGE},
  865. X    {"nDown line      ", VDOWNLINE},{"nDown column",    VDOWNCOL},
  866. X    {" Buffer end     ", VBOTTOM},    {"nEdit rpt buffer",    VEDITRPT},
  867. X    {"nFind",            VSEARCH},    {" Find cross-buff",    VNEXT},
  868. X    {" Get save buffer", VGET},    {" Unkill lastline",    VUNKILL},
  869. X    {"nHalf page      ", VHALFP},    {"nInsert (to ESC)",    VINSERT},
  870. X    {" Jump back",         VJUMP},    {"nKill character ",    VDELNEXT},
  871. X    {"nKill line      ", VKILLALL},    {"nLeft",        VLEFT},
  872. X    {" Memory status  ", VMEMORY},    {"nNote location  ",    VNOTELOC},
  873. X    {"nReset loc",         VRETNOTE},    {"nOpen line      ",    VOPENLINE},
  874. X    {" Call Opr system", VSYSTEM},    {"nPage",        VFLIP},
  875. X    {" Print screen   ", VPRINTS},    {"nRight          ",    VRIGHT},
  876. X    {" Restore rpt buf", VSTORERPT},{"nSave lines     ",    VSAVE},
  877. X    {"nTidy, fill text", VTIDY},    {" Abort",        VABORT},
  878. X    {"nUp             ", VUPLINE},    {"nUp column      ",    VUPCOL},
  879. X    {" Verify screen",   VVERIFY},    {"nWrite buffer   ",    VWPAGE},
  880. X    {" Exit, end edit ", VQUIT},    {"nYank file",        VYANK},
  881. X    {"nDel prev char  ", VDELLAST},    {"nFind again     ",    VSAGAIN},
  882. X    {" Del last",         VREMOVE},    {" Change last    ",    VRMVINS},
  883. X    {" Del to line beg", VKILLPREV},{" Del to line end",    VKILLREST},
  884. X    {" Line begining  ", VBEGLINE},    {" Line end       ",    VENDLINE},
  885. X    {"nWord right",         VMVWORD},    {"nWord left      ",    VMVBWORD},
  886. X    {"nRepeat again   ", VXREPEAT},    {"nk Exec rpt k n times",VEXECRPT},
  887. X    {"n p Set param p ", VSETPARS},    {" Help           ",    VHELP},
  888. X    {" Insert find pat",     VINSPAT},{"nChange case      ",VFOLDCASE},
  889. X    {"/",0}            /* last variable entry */
  890. X      };
  891. X
  892. Xremark("Commands settable by this program:  (n => count allowed):");
  893. X    for (hnum = fields = 0  ; ; ++hnum )
  894. X      {
  895. X    prompt("   ");
  896. X    cp = cmddes[hnum].hmsg;
  897. X    if (*cp == '/')    /* end of variable list */
  898. X        break;
  899. X    else
  900. X        shocout(*cp);    /* show n or blank */
  901. X    msg = ++cp;        /* where message is, skipping 'n' field */
  902. X    while (*cp)        /* ship to lex value */
  903. X        ++cp;
  904. X    i = cmddes[hnum].Vmsg;        /* get the lexical index */
  905. X    shocout(cupper(lexsym[i]));    /* show the command */
  906. X    if (lexsym[i] >= ' ')
  907. X        shocout(' ');    /* skip space for no '^' */
  908. X
  909. X    shocout(' ');        /* space to separate */
  910. X    prompt(msg);        /* and show the message */
  911. X    if (++fields == 3)    /* bump fields, see if need newline */
  912. X      {
  913. X        fields = 0;
  914. X        remark("");
  915. X      }
  916. X      }
  917. X    remark("");
  918. Xremark("Note: <> repeat, @ command file, and ESCAPE cannot be changed.");
  919. X  }
  920. X
  921. X/* =============================>>> SHOCOUT <<<============================= */
  922. X  shocout(c)
  923. X  char c;
  924. X  {
  925. X
  926. X    if (c < ' ')
  927. X      {
  928. X    printf("^%c",c + '@');
  929. X      }
  930. X    else
  931. X    printf("%c",c);
  932. X  }
  933. X
  934. X/* ===============================>>> FUNKEYS <<<========================*/
  935. X  funkeys()
  936. X  {
  937. X
  938. X    SLOW int j,i,val;
  939. X    SLOW int fun;
  940. X
  941. XFAGAIN:
  942. X    cls();
  943. X    remark("You may now define up to 49 function keys to be translated to");
  944. X    remark("commands OR letters.  This translation will take place before");
  945. X    remark("the editor gets the character at any level  -- thus the translation");
  946. X    remark("will apply equally to command mode and insert mode.  The translation");
  947. X    remark("assumes each function key generates a 2 character sequence.  The");
  948. X    remark("first character is an 'escape' character that must be the same for");
  949. X    remark("each key.  If the 'escape' character is really ESC, then you must");
  950. X    remark("also define one function key to have ESC as its translation value.");
  951. X    remark("When asked for the function key, simply press the key, followed by");
  952. X    remark("RETURN.  Enter either the character or decimal value of the translation.");
  953. X
  954. X    for (i = 0 ; i < 50 ; ++i)
  955. X      {
  956. X    funchar[i] = funcmd[i] = 0;
  957. X      }
  958. X
  959. X    BL;
  960. X    prompt("Do you want to define any function keys? (y/n) ");
  961. X    lreply(rp,10);
  962. X    if (*rp == 'n')
  963. X    goto WTFUN;
  964. X
  965. X    BL;
  966. X    remark("Now, please press ANY function key so the program can identify");
  967. X    prompt("the 'function key escape' code (followed by a RETURN): ");
  968. X    reply(rp,10);
  969. X    funesc = *rp;        /* this should be the escape char */
  970. X    if (funesc == 27)
  971. X      {
  972. X    BL;
  973. X    remark("IMPORTANT:  You MUST define a function key to send an ESCAPE (decimal 27).");
  974. X    remark("If you don't, then you won't be able to end insert mode or repeat loops.");
  975. X    remark("The program doesn't have logic to make sure you do this, so don't forget!");
  976. X    BL;
  977. X      }
  978. X
  979. X    for (i = 0 ; i < 50 ; ++i)
  980. X      {
  981. XFUNAGAIN:
  982. X    prompt("Press function key to define (RETURN only to exit): ");
  983. X     rp[1] = 0;
  984. X    reply(rp,10);
  985. X    fun = rp[1];
  986. X    if (rp[1] == 0)
  987. X        break;
  988. X    for (j = 0 ; j < 50 ; ++j)
  989. X      {
  990. X        if (fun == funchar[j])
  991. X          {
  992. X        remark("That's been used already, try again.");
  993. X        goto FUNAGAIN;
  994. X          }
  995. X      }
  996. X    funchar[i] = fun;
  997. X    prompt("Now enter the character/command it gets translated to: ");
  998. X    reply(rp,10);
  999. X    val = getval(rp);
  1000. X    funcmd[i] = val;
  1001. X      }
  1002. X
  1003. X    cls();
  1004. Xremark("Functions have been defined. You can start over if you made any mistakes.");
  1005. X    remark("");
  1006. X    prompt("Are they ok? (y/n) ");
  1007. X    lreply(rp,10);
  1008. X    if (*rp == 'n')
  1009. X    goto FAGAIN;
  1010. X
  1011. XWTFUN:
  1012. X    for (i = 0 ; i < 50 ; ++i)
  1013. X      {
  1014. X    fputc(funchar[i],f);
  1015. X      }
  1016. X    for (i = 0 ; i < 50 ; ++i)
  1017. X      {
  1018. X    fputc(funcmd[i],f);
  1019. X      }
  1020. X    fputc(funesc,f);
  1021. X  }
  1022. X  
  1023. X
  1024. X/* ===============================>>> GETVAL <<<========================*/
  1025. X  getval(str)
  1026. X  char *str;
  1027. X  {
  1028. X    /* return one byte value */
  1029. X
  1030. X    if (*str >= '0' && *str <= '9')
  1031. X    return (atoi(str));
  1032. X    else
  1033. X    return (*str & 0377);
  1034. X  }
  1035. X
  1036. X/* ===============================>>> SET <<<========================*/
  1037. X  set()
  1038. X  {
  1039. X    /* set newlex[indx] to a new value */
  1040. X
  1041. X    SLOW int val,i, oldi;
  1042. X
  1043. XSAGAIN:
  1044. Xprompt("Enter current command to change (key or decimal value, RETURN to exit) ");
  1045. X    reply(rp,10);
  1046. X    val = clower(getval(rp));
  1047. X
  1048. X    if (val == 0)
  1049. X      {
  1050. X    return 0;
  1051. X      }
  1052. X    for (oldi = 1 ; oldi <= LEXVALUES ; ++oldi)
  1053. X      {
  1054. X    if (val == lexsym[oldi])
  1055. X      {
  1056. X        goto HAVEIT;
  1057. X      }
  1058. X      }
  1059. X    
  1060. X    return -1;    
  1061. X    
  1062. XHAVEIT:
  1063. X    prompt("Enter NEW command (key or decimal value, RETURN to exit) ");
  1064. X    reply(rp,10);
  1065. X    val = clower(getval(rp));
  1066. X    if (val == 0 || val == '@' || val == 27 || val == '<' || val == '>')
  1067. X    return -1;
  1068. X    for (i = 1 ; i <= LEXVALUES ; ++i)
  1069. X      {
  1070. X    if (val == lexsym[i])
  1071. X      {
  1072. X        return -1;        /* duplicate */
  1073. X      }
  1074. X      }
  1075. X    lexsym[oldi] = val;
  1076. X    return 1;
  1077. X  }
  1078. X
  1079. X/* ===============================>>> SYNO <<<========================*/
  1080. X  syno()
  1081. X  {
  1082. X
  1083. X    SLOW int j, i, valfrom, valto, found;
  1084. X    
  1085. XSAGAIN:
  1086. X    cls();
  1087. X    remark("You may now define up to 19 synonyms.  For example, you might");
  1088. X    remark("want to define a space to be a synonym for right, or RETURN");
  1089. X    remark("the same as down.  You must use unused values, however.  You");
  1090. X    remark("can't use a existing command as a synonym.  You may enter the");
  1091. X    remark("character followed by a RETURN, or the decimal value of the key.");
  1092. X
  1093. X    for (i = 0 ; i < 20 ; ++i)
  1094. X      {
  1095. X    synofr[i] = synoto[i] = 0;
  1096. X      }
  1097. X
  1098. X    for (i = 0 ; i < 19 ; ++i)
  1099. X      {
  1100. XSYNAGAIN:
  1101. X    BL;
  1102. X    prompt("Enter the new synonym (RETURN when done): ");
  1103. X    reply(rp,10);
  1104. X    valfrom = getval(rp);
  1105. X    if (valfrom == 0)
  1106. X        break;
  1107. X    for (j = 1 ; j <= LEXVALUES ; ++j)
  1108. X      {
  1109. X        if (lexsym[j] == valfrom)
  1110. X          {
  1111. X        remark("That is already a command! Try again.");
  1112. X        goto SYNAGAIN;
  1113. X          }
  1114. X      }
  1115. X    prompt("Enter the equivalent command: ");
  1116. X    reply(rp,10);
  1117. X    valto = getval(rp);
  1118. X    for (j = 1, found = FALSE ; j <= LEXVALUES ; ++j)
  1119. X      {
  1120. X        if (lexsym[j] == valto)
  1121. X            found = TRUE;
  1122. X      }
  1123. X    if (!found)
  1124. X      {
  1125. X        remark("That is not a defined command. Try again.");
  1126. X        goto SYNAGAIN;
  1127. X      }
  1128. X
  1129. X    synofr[i] = valfrom;
  1130. X    synoto[i] = valto;
  1131. X      }
  1132. X    cls();
  1133. X
  1134. Xremark("Synonyms have been defined. You can start over if you made any mistakes.");
  1135. X    remark("");
  1136. X    prompt("Are they ok? (y/n) ");
  1137. X    lreply(rp,10);
  1138. X    if (*rp == 'n')
  1139. X    goto SAGAIN;
  1140. X
  1141. X    for (i = 0 ; i < 20 ; ++i)
  1142. X        fputc(synofr[i],f);
  1143. X    for (i = 0 ; i < 20 ; ++i)
  1144. X        fputc(synoto[i],f);
  1145. X
  1146. X  }
  1147. X
  1148. X/* ===============================>>> CLS <<<========================*/
  1149. X  cls()
  1150. X  {
  1151. X    int i;
  1152. X    for (i = 0 ; i < 25 ; ++i)
  1153. X    remark("");
  1154. X  }
  1155. X
  1156. X/* ===============================>>> short_CLS <<<========================*/
  1157. X  short_cls()
  1158. X  {
  1159. X    int i;
  1160. X    for (i = 0 ; i < 10 ; ++i)
  1161. X    remark("");
  1162. X  }
  1163. X
  1164. X#define EXTENDED    /* my own extended lib functions */
  1165. X/* #define STANDARD    /* the set of standard functions i use */
  1166. X#define LOCAL static    /* make all local globals, i think */
  1167. X
  1168. X#ifdef EXTENDED
  1169. X/*=============================>>> CLOWER  <<<================================*/
  1170. X  char clower(ch)
  1171. X  char ch;
  1172. X  {
  1173. X    return ((ch >='A' && ch<='Z') ? ch + ' ' : ch);
  1174. X  }
  1175. X
  1176. X/*=============================>>> CUPPER  <<<================================*/
  1177. X  char cupper(ch)
  1178. X  char ch;
  1179. X  {
  1180. X    return ((ch >= 'a' && ch <= 'z') ? ch - ' ' : ch);
  1181. X  }
  1182. X
  1183. X/* =========================>>> LOWER  <<<==============================*/
  1184. X  lower(str)
  1185. X  char str[];
  1186. X  {
  1187. X    SLOW int i;
  1188. X
  1189. X    for (i=0 ; str[i] ; ++i)
  1190. X    str[i]=clower(str[i]);
  1191. X
  1192. X  }
  1193. X
  1194. X/*=============================>>> PROMPT <<<================================*/
  1195. X  prompt(msg)
  1196. X  char msg[];
  1197. X  {
  1198. X    printf("%s",msg);
  1199. X  }
  1200. X
  1201. X
  1202. X/*=============================>>> REMARK <<<================================*/
  1203. X  remark(msg)
  1204. X  char msg[];
  1205. X  {
  1206. X    printf("%s\n",msg);
  1207. X  }
  1208. X
  1209. X/*=============================>>> UPPER  <<<================================*/
  1210. X  upper(str)
  1211. X  char str[];
  1212. X  {
  1213. X    static int i;
  1214. X
  1215. X    for (i=0 ; str[i] ; ++i)
  1216. X    str[i]=cupper(str[i]);
  1217. X  }
  1218. X
  1219. X
  1220. X/*=============================>>> LREPLY <<<================================*/
  1221. X  lreply(msg,maxc)
  1222. X  char msg[];
  1223. X  int maxc;
  1224. X  {
  1225. X    reply(msg,maxc);
  1226. X    lower(msg);
  1227. X  }
  1228. X
  1229. X/*=============================>>> UREPLY <<<================================*/
  1230. X  ureply(msg,maxc)
  1231. X  char msg[];
  1232. X  int maxc;
  1233. X  {
  1234. X    reply(msg,maxc);
  1235. X    upper(msg);
  1236. X  }
  1237. X
  1238. X/*=============================>>> REPLY <<<================================*/
  1239. X  reply(msg,maxc)
  1240. X  char msg[];
  1241. X  int maxc;
  1242. X  {
  1243. X#ifdef UNIX
  1244. X    gets(msg);
  1245. X#else
  1246. X    mreply(msg,maxc);
  1247. X#endif
  1248. X  }
  1249. X
  1250. X/*=============================>>> RDINT <<<================================*/
  1251. X  rdint(val)
  1252. X  int *val;
  1253. X  {
  1254. X    char chrrep[12];
  1255. X    reply(chrrep,11);
  1256. X    *val = atoi(chrrep);
  1257. X  }
  1258. X#endif
  1259. X#ifndef UNIX
  1260. X/*=============================>>> MREPLY <<<================================*/
  1261. X  mreply(msg,maxc)
  1262. X  char msg[];
  1263. X  int maxc;
  1264. X  {
  1265. X#define CBS 8        /* Backspace */
  1266. X#define CDL1 21        /* ^U */
  1267. X#define CDL2 24        /* ^X */
  1268. X#define CABORT 3    /* ^C */
  1269. X#define CRET 13        /* cr */
  1270. X#define BACKSPACE 8
  1271. X
  1272. X    static char ch, rp;
  1273. X    static int i;
  1274. X
  1275. X
  1276. X    for (i = 0 ; i < maxc ; )    /* i -> next char */
  1277. X      {
  1278. X    ch = ttrd_();     /* read the character */
  1279. X    if (ch == CBS)        /* back space */
  1280. X      {
  1281. X        if (i > 0)        /* must be something to delete */
  1282. X          {
  1283. X        --i;        /* wipe out char */
  1284. X        ttwt_(BACKSPACE); ttwt_(' '); ttwt_(BACKSPACE);
  1285. X        if (msg[i] < ' ')    /* double echo ^ chrs */
  1286. X          {
  1287. X            ttwt_(BACKSPACE); ttwt_(' '); ttwt_(BACKSPACE);
  1288. X          }
  1289. X          }
  1290. X      }
  1291. X#ifdef USE_WIPE
  1292. X    else if (ch == CDL1 || ch == CDL2)    /* wipe whole line */
  1293. X      {
  1294. X        i = 0;        /* set for loop ++ */
  1295. X        remark("#");
  1296. X        prompt("Re-enter? ");
  1297. X      }
  1298. X#endif
  1299. X    else if (ch == CABORT)
  1300. X      {
  1301. X        remark("^C");
  1302. X        prompt("Exit to operating system - are you sure? (y/n) ");
  1303. X        rp = ttrd_();
  1304. X        if (rp == 'y' || rp =='Y')
  1305. X         {
  1306. X        remark("y");
  1307. X        exit(0);
  1308. X         }
  1309. X        remark("n");
  1310. X        msg[i] = 0;
  1311. X        prompt("Re-enter? "); prompt(msg);        /* re-echo */
  1312. X      }
  1313. X    else if (ch == CRET)        /* ret, so done */
  1314. X      {
  1315. X        remark("");
  1316. X        msg[i] = 0;
  1317. X        return;
  1318. X      }
  1319. X    else
  1320. X      {
  1321. X        msg[i++] = ch;
  1322. X        msg[i] = 0;            /* always 0 terminate */
  1323. X        if (ch < ' ')
  1324. X          {
  1325. X        ch += '@';
  1326. X        ttwt_('^');
  1327. X          }
  1328. X        ttwt_(ch);            /* echo char */
  1329. X      }
  1330. X      } /* end for */
  1331. X
  1332. X    remark("");
  1333. X  }
  1334. X
  1335. X/*=============================>>> ttrd_ <<<================================*/
  1336. X  ttrd_()
  1337. X  {
  1338. X#ifdef MSDOS
  1339. X    return (bdos(7,-1) & 0377);
  1340. X#endif
  1341. X#ifdef GEMDOS
  1342. X    return (gemdos(7) & 0377);
  1343. X#endif
  1344. X  }
  1345. X
  1346. X/*=============================>>> ttwt_ <<<================================*/
  1347. X  ttwt_(c)
  1348. X  char c;
  1349. X  {
  1350. X    fprintf(stderr,"%c",c);
  1351. X  }
  1352. X#endif
  1353. X/* -------------------------- tvx_cfg.c --------------------------- */
  1354. SHAR_EOF
  1355. echo Extracting tvx_ptch.c:
  1356. sed 's/^X//' >tvx_ptch.c <<\SHAR_EOF
  1357. X/* -------------------------- tvx_ptch.c --------------------------- */
  1358. X#include "tvx_defs.ic"
  1359. X
  1360. X#define EXTERN
  1361. X#include "tvx_glbl.ic"
  1362. X
  1363. X/*=======================================================================
  1364. X
  1365. X    tvpatch - program to patch tvx with config.tvx file
  1366. X
  1367. X    first version 6/19/84
  1368. X    7/25/84 - fixed to correspond to tvx version, add extra command
  1369. X    2/14/85 - version to correspond with rest
  1370. X    5/15/85 - again, batched to correspond
  1371. X    9/20/85 - fixed for new version of tvx, unix added
  1372. X
  1373. X======================================================================= */
  1374. X#ifndef UNIX
  1375. X    char filein[] = "A:TVX.EXE";
  1376. X    char fileout[]= "A:TEMP1.$$$";
  1377. X#else
  1378. X    char filein[80] = "tvx";
  1379. X    char fileout[80]= "tvx_temp";
  1380. X#endif
  1381. X    char config[80];
  1382. X
  1383. X
  1384. X/*  define our general control item structure for general patching */
  1385. X
  1386. X#define BL remark("")
  1387. X#define RMK remark
  1388. X#define PR prompt
  1389. X    char clower(), cupper();
  1390. X    extern char *malloc();
  1391. X    extern FILE *fopen();
  1392. X    FILE *tvxin, *cfgin, *tvxout;
  1393. X
  1394. X/* =============================>>> MAIN   <<<============================= */
  1395. X  main()
  1396. X  {
  1397. X    char ans[80];
  1398. X
  1399. XTOP:
  1400. X    cls();
  1401. X    RMK("TVX_PTCH - Version 11/12/85");
  1402. X    BL;
  1403. XRMK("  This program is used to permanently alter TVX to match the options");
  1404. XRMK("selected with the TVX_CNFG program.  It will read in the configuration");
  1405. XRMK("file you specify (such as CONFIG.TVX), and patch TVX to reflect those");
  1406. XRMK("values.  Then you won't need to use the '-c' switch when using TVX.");
  1407. X    BL;
  1408. XRMK("*** You may press CONTROL-C at any time to cancel this installation. ***");
  1409. X
  1410. X    do 
  1411. X      {
  1412. X    BL;
  1413. X#ifndef UNIX
  1414. X    PR("On which drive is TVX.EXE located? (A, B, ...): ");
  1415. X    ureply(ans,10);
  1416. X    filein[0] = ans[0];
  1417. X#endif
  1418. X    if ( !(tvxin = fopen(filein,FILEREAD)))
  1419. X      {
  1420. X        PR("TVX not found on specified drive, try again: ");
  1421. X        RMK(filein);
  1422. X#ifdef UNIX
  1423. X        PR("Please enter name of tvx executable file: ");
  1424. X        reply(filein,79);
  1425. X#endif
  1426. X        continue;
  1427. X      }
  1428. X    fclose(tvxin);
  1429. X    break;
  1430. X      }
  1431. X    while (1);
  1432. X
  1433. X#ifndef UNIX
  1434. X    fileout[0] = cupper(ans[0]);
  1435. X#endif
  1436. X    do 
  1437. X      {
  1438. X    BL;
  1439. X    PR("Enter the name of the configuration file to use: ");
  1440. X    reply(config,79);
  1441. X    if ( !(cfgin = fopen(config,FILEREAD)))
  1442. X      {
  1443. X        RMK("Configuration not found on specified drive, try again.");
  1444. X        continue;
  1445. X      }
  1446. X
  1447. X    rdcfg(lexsym,LEXVALUES+1);
  1448. X    rdcfg(synofr,20);
  1449. X    rdcfg(synoto,20);
  1450. X    rdcfg(funchar,50);
  1451. X    rdcfg(funcmd,50);
  1452. X    rdcfg(&funkey,1);
  1453. X    rdcfg(&autoin,1);
  1454. X    rdcfg(&ddline,1);
  1455. X    rdcfg(&dscrl,1);
  1456. X    rdcfg(&dxcase,1);
  1457. X    rdcfg(&wraplm,1);
  1458. X    rdcfg(&use_wild,1);
  1459. X    rdcfg(&usebak,1);
  1460. X    logdef = usebak;
  1461. X    rdcfg(&cut_mode,1);
  1462. X#ifdef MSDOS
  1463. X    rdcfg(&usecz,1);
  1464. X#endif
  1465. X    fclose(cfgin);
  1466. X    break;
  1467. X      }
  1468. X    while (1);
  1469. X    BL;
  1470. X    RMK("TVX is being modified to match your choices.");
  1471. X    RMK("This may take several minutes.");
  1472. X    BL;
  1473. X    fpatch(filein);    /* patch tvx */
  1474. X    cls();
  1475. X    RMK("Modification completed.  TVX is ready to use without the -c now.");
  1476. X    BL;
  1477. X  }
  1478. X
  1479. X/* =============================>>> RDCFG <<<============================= */
  1480. X  rdcfg(toset,cnt)
  1481. X  char *toset;
  1482. X  int cnt;
  1483. X    {    /* read cnt vals from cfgin */
  1484. X
  1485. X    FAST int i,val;
  1486. X
  1487. X    for (i = 0 ; i < cnt ; ++i)
  1488. X      {
  1489. X    if ((val = fgetc(cfgin)) == EOF)
  1490. X     {
  1491. X        remark("Invalid configuration file, aborting");
  1492. X        fclose(cfgin);
  1493. X        exit(999);
  1494. X     }
  1495. X    *toset++ = val;    /* replace with new commands */
  1496. X      }
  1497. X  }
  1498. X
  1499. X/* =============================>>> FPATCH <<<============================= */
  1500. X  fpatch(fn)
  1501. X  char *fn;
  1502. X  {
  1503. X    static int byt;
  1504. X    static int i;
  1505. X    static int didpatch;
  1506. X    static char *begptr;    /* patch area pointers */
  1507. X    prompt("Patching "); remark(filein);
  1508. X
  1509. X#ifndef UNIX
  1510. X    fn[0] = fileout[0];        /* set drive */
  1511. X#endif
  1512. X    didpatch = FALSE;
  1513. X    if (!(tvxin = fopen(fn,FILEREAD)))
  1514. X      {
  1515. X    PR("Unable to find file to patch: "); PR(fn);
  1516. X        RMK(".  Aborting to operating system.");
  1517. X    exit(999);
  1518. X      }
  1519. X    if (!(tvxout = fopen(fileout,FILEWRITE)))
  1520. X      {
  1521. X    PR("Unable to create new file, aborting: ");
  1522. X    RMK(fileout);
  1523. X    exit(999);
  1524. X      }
  1525. X    while ((byt = fgetc(tvxin)) != EOF)
  1526. X      {
  1527. X    fputc(byt,tvxout);
  1528. X    if (byt == '#')            /* look for first sharp */
  1529. X      {
  1530. X        for (i = 1 ; i <= 4 ; ++i)
  1531. X          {
  1532. X        if ((byt = fgetc(tvxin)) == EOF)
  1533. X            goto l900;
  1534. X        fputc(byt,tvxout);    /* echo */
  1535. X        if (byt != '#')
  1536. X            goto l800;
  1537. X          }
  1538. X        byt = fgetc(tvxin);        /* should be : next */
  1539. X        fputc(byt,tvxout);
  1540. X        if (byt != ':')
  1541. X        goto l800;
  1542. X
  1543. X/*   fall thru means found patch area -- code to patch follows */
  1544. X
  1545. X        for (begptr = (char *) &addx ; begptr < (char *) &endpatch ;
  1546. X          ++begptr)
  1547. X          {
  1548. X        if ((byt = fgetc(tvxin)) == EOF) /* read byte from file */
  1549. X            goto l900;
  1550. X        fputc(*begptr,tvxout); /* replace with byte from my area */
  1551. X          }
  1552. X        didpatch = TRUE;
  1553. X      }
  1554. Xl800:    byt = byt;        /* compiler bug */
  1555. X      }
  1556. X
  1557. X
  1558. Xl900:
  1559. X    fclose(tvxin);
  1560. X    fclose(tvxout);
  1561. X    if (!didpatch)
  1562. X      {
  1563. X    RMK("*********  ERROR ********");
  1564. X    RMK("The file just checked was not a proper version of the program!");
  1565. X    RMK("Please check that your are using a valid copy of the");
  1566. X    RMK("program file supplied with this initialization program!");
  1567. X    RMK("Unable to make patch, aborting");
  1568. X    exit(999);
  1569. X      }
  1570. X    unlink(fn);
  1571. X    fn[0] = fileout[0];        /* fix the drive */
  1572. X    if (rename(fileout,fn) != 0)
  1573. X      {
  1574. X    RMK("Unable to rename temporary patch file");
  1575. X    exit(999);
  1576. X      }
  1577. X  }
  1578. X
  1579. X/* =============================>>> OK <<<============================= */
  1580. X  ok(msg)
  1581. X  char *msg;
  1582. X  {
  1583. X    char rp[11];
  1584. X    PR(msg); PR(" (y/n) ");
  1585. X    lreply(rp,10);
  1586. X    return (rp[0] == 'y');
  1587. X  }
  1588. X
  1589. X/* ============================>>> RVALID <<<=========================== */
  1590. X  rvalid(chr,okstr)
  1591. X  char chr,*okstr;
  1592. X  {
  1593. X    /* sees if chr is in okstr */
  1594. X   
  1595. X    SLOW int i;
  1596. X    SLOW char ch;
  1597. X
  1598. X    ch = clower(chr);
  1599. X    while (*okstr)
  1600. X      {
  1601. X    if (ch == clower(*okstr++))
  1602. X        return TRUE;
  1603. X      }
  1604. X    return FALSE;
  1605. X  }
  1606. X  
  1607. X/* =============================>>> CLS  <<<============================= */
  1608. X  cls()
  1609. X  {
  1610. X    int i;
  1611. X    for (i = 0  ; i < 25 ; ++i)
  1612. X    BL;
  1613. X  }
  1614. X
  1615. X#define EXTENDED    /* my own extended lib functions */
  1616. X/* #define STANDARD    /* the set of standard functions i use */
  1617. X#define LOCAL static    /* make all local globals, i think */
  1618. X
  1619. X
  1620. X#ifdef EXTENDED
  1621. X/*=============================>>> CLOWER  <<<================================*/
  1622. X  char clower(ch)
  1623. X  char ch;
  1624. X  {
  1625. X    return ((ch >='A' && ch<='Z') ? ch + ' ' : ch);
  1626. X  }
  1627. X
  1628. X/*=============================>>> CUPPER  <<<================================*/
  1629. X  char cupper(ch)
  1630. X  char ch;
  1631. X  {
  1632. X    return ((ch >= 'a' && ch <= 'z') ? ch - ' ' : ch);
  1633. X  }
  1634. X
  1635. X/* =========================>>> LOWER  <<<==============================*/
  1636. X  lower(str)
  1637. X  char str[];
  1638. X  {
  1639. X    FAST int i;
  1640. X
  1641. X    for (i=0 ; str[i] ; ++i)
  1642. X    str[i]=clower(str[i]);
  1643. X
  1644. X  }
  1645. X
  1646. X/*=============================>>> PROMPT <<<================================*/
  1647. X  prompt(msg)
  1648. X  char msg[];
  1649. X  {
  1650. X    printf("%s",msg);
  1651. X  }
  1652. X
  1653. X
  1654. X/*=============================>>> REMARK <<<================================*/
  1655. X  remark(msg)
  1656. X  char msg[];
  1657. X  {
  1658. X    printf("%s\n",msg);
  1659. X  }
  1660. X
  1661. X/*=============================>>> UPPER  <<<================================*/
  1662. X  upper(str)
  1663. X  char str[];
  1664. X  {
  1665. X    static int i;
  1666. X
  1667. X    for (i=0 ; str[i] ; ++i)
  1668. X    str[i]=cupper(str[i]);
  1669. X  }
  1670. X
  1671. X
  1672. X/*=============================>>> LREPLY <<<================================*/
  1673. X  lreply(msg,maxc)
  1674. X  char msg[];
  1675. X  int maxc;
  1676. X  {
  1677. X    reply(msg,maxc);
  1678. X    lower(msg);
  1679. X  }
  1680. X
  1681. X/*=============================>>> UREPLY <<<================================*/
  1682. X  ureply(msg,maxc)
  1683. X  char msg[];
  1684. X  int maxc;
  1685. X  {
  1686. X    reply(msg,maxc);
  1687. X    upper(msg);
  1688. X  }
  1689. X
  1690. X/*=============================>>> REPLY <<<================================*/
  1691. X  reply(msg,maxc)
  1692. X  char msg[];
  1693. X  int maxc;
  1694. X  {
  1695. X#ifdef UNIX
  1696. X    gets(msg);
  1697. X#endif
  1698. X#ifdef MSDOS
  1699. X    gets(msg,maxc,stdin);
  1700. X#endif
  1701. X#ifdef GEMDOS
  1702. X    gemdos(0x0a,msg);
  1703. X#endif
  1704. X  }
  1705. X
  1706. X/*=============================>>> RDINT <<<================================*/
  1707. X  rdint(val)
  1708. X  int *val;
  1709. X  {
  1710. X    char chrrep[12];
  1711. X    reply(chrrep,11);
  1712. X    *val = atoi(chrrep);
  1713. X  }
  1714. X#endif
  1715. X/* -------------------------- tvx_ptch.c --------------------------- */
  1716. SHAR_EOF
  1717. echo ALL DONE!
  1718. exit 0
  1719.  
  1720.